<template>
	<view class="content">
		<z-paging ref="paging" v-model="items" @query="initLoad">
			<view class="bg-white padding-lr solid-top">
				<app-list-item sign="collect" :item="item" v-for="(item, index) in items" :key="index" @handleHref="handleHref" @handleShare="handleShare" :showActions="true" solidStyle="solid-bottom padding-bottom"></app-list-item>
			</view>
		</z-paging>
	</view>
</template>

<script>
	import {
		friendlyDate
	} from '@/common/util.js';

	import {
		meCollect as meCollectApi
	} from '@/api/user/meCollect.js'
	
	import appListItem from '@/components/app-list-item.vue';

	export default {
		components: {
			appListItem
		},
		data() {
			return {
				items: []
			}
		},
		onLoad(options) {
			this.initLoad()
		},
		methods: {
			initLoad() {
				let params1 = {
					cmd: 'LunTan_PraiseInfo',
					nUid: uni.getStorageSync('uid'),
					page: 1
				};
				let params = JSON.stringify(params1);

				meCollectApi(params).then(res => {
					let data = res.data || [];
					let items = [];
					
					if (data.length > 0) {
						items = data.filter(item => {
							item.avatar = 'https://ossweb-img.qq.com/images/lol/web201310/skin/big10006.jpg';

							return item;
						})
					}
					this.$refs.paging.complete(items);
				}).catch(err => {
					this.$refs.paging.complete(false);
				})
			},
			handleHref(news) {
				if (typeof news === 'object') {
					let item = {
						id: news.nID,
						newsid: news.nID,
						datetime: friendlyDate(new Date(news.create_time.replace(/\-/g, '/')).getTime()),
						title: news.title || '',
						content: news.sContent || '',
						image_url: news.cover || '',
						source: news.author_name || '',
						comment_count: news.nComment || '0',
						praise_count: news.nPraise || '0',
						images: []
					};

					uni.navigateTo({
						url: `../../strategy/detail?query=${JSON.stringify(item)}`
					})
				}
			}
		}
	}
</script>

<style>
</style>
